package com.chenza.stock.controller;

import java.io.IOException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class SendMsg_webchinese {
	public static void main(String[] args) throws HttpException, IOException {
		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://gbk.api.smschinese.cn");
		// 在请求头中设置编码格式
		post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gbk");
		NameValuePair[] data = {
			//设置用户名
			new NameValuePair("Uid","chenza"),
			//设置密钥
			new NameValuePair("Key","dc270cd2e083b37fc2d7"),
			//设置目标手机号码
			new NameValuePair("smsMob","13880537297"),
			//设置短信内容
			new NameValuePair("smsText","给我一秒钟，我会想起你，给我一分钟，我会牵挂你，给我一整天，我会思念你，给我一辈子，我会守护你，给我一条短信倾诉，我会说：我想你了!【陈治安科技有限公司】")
		};
		// 设置请求内容
		post.setRequestBody(data);
		
		// 执行网络请求
		client.executeMethod(post);
		//打印日志
		Header[] headers=post.getRequestHeaders();
		int statusCode=post.getStatusCode();
		System.out.println("statusCode:"+statusCode);
		for (Header h : headers) {
			System.out.println(h.toString());
		}
		String result=new String(post.getResponseBodyAsString().getBytes("GBK"));
		System.out.println(result);
		
		//连接不能重用的时候关闭连接
		post.releaseConnection();
	}
}
